package com.codechuan.demo.utils;

import android.content.Context;
import android.widget.Toast;

import androidx.appcompat.app.AlertDialog;
import com.codechuan.demo.common.Constant;

public class DialogUtil {

    public static AlertDialog.Builder showDialog(String title,String msg) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Constant.context);
        builder.setTitle(title);
        builder.setMessage(msg);
        // 设置确定按钮的点击事件
        builder.setPositiveButton("确定", (dialog, which) -> {
            // 点击确定按钮后的操作
        });
        // 设置取消按钮的点击事件
        builder.setNegativeButton("取消", (dialog, which) -> {
            // 点击取消按钮后的操作
        });
        return builder;
    }

    public static AlertDialog.Builder showNoBind(String title,String msg) {
        AlertDialog.Builder builder = new AlertDialog.Builder(Constant.context);
        builder.setTitle(title);
        builder.setMessage(msg);
        // 设置确定按钮的点击事件
        builder.setPositiveButton("确定", (dialog, which) -> {
            // 点击确定按钮后的操作
            Constant.executorService.execute(() -> {
                String message = MyHttpUtil.noBindAccount(Constant.USER_ACCOUNT);
                Constant.handler.post(()->{
                   DialogUtil.showDialog(Constant.context,message);
                });
            });
        });
        // 设置取消按钮的点击事件
        builder.setNegativeButton("取消", (dialog, which) -> {
            // 点击取消按钮后的操作
        });
        return builder;
    }

    public  static void showDialog(Context context, String msg) {
        Toast.makeText(context, msg, Toast.LENGTH_SHORT).show();
    }
}
